/**
 * @(#) WorkTimeMediator.as
 *
 * @date		2009. 02. 25.
 * @version		1.0
 * @author		Shin, Yunwoo
 * @description	근무 - Mediator
 * 				근무관리 Presentation Logic을 관리 
 */
package com.skt.common_hr.work_sac.view 
{
	import com.skt.common_hr.common.Variables;
	import com.skt.common_hr.common.calendar.DailyItem;
	import com.skt.common_hr.common.calendar.Holiday;
	import com.skt.common_hr.common.components.CommonAlert;
	import com.skt.common_hr.common.puremvc.OverViewMediator;
	import com.skt.common_hr.work_sac.WorkFacade;
	import com.skt.common_hr.work_sac.events.WorkTimeEvent;
	import com.skt.common_hr.work_sac.model.CalendarProxy;
	import com.skt.common_hr.work_sac.model.DateRangeProxy;
	import com.skt.common_hr.work_sac.model.OverTimeSumProxy;
	import com.skt.common_hr.work_sac.model.ReqWorkTimeProxy;
	import com.skt.common_hr.work_sac.model.TeamVacationProxy;
	import com.skt.common_hr.work_sac.model.VacationCodeProxy;
	import com.skt.common_hr.work_sac.model.VacationListProxy;
	import com.skt.common_hr.work_sac.model.VacationQuotaProxy;
	import com.skt.common_hr.work_sac.model.vo.DateVO;
	import com.skt.common_hr.work_sac.model.vo.TeamVacationVO;
	import com.skt.common_hr.work_sac.model.vo.VacationVO;
	import com.skt.common_hr.work_sac.view.components.ModVacationView;
	import com.skt.common_hr.work_sac.view.components.ModWorkTimeView;
	import com.skt.common_hr.work_sac.view.components.ReadVacationView;
	import com.skt.common_hr.work_sac.view.components.ReadWorkTimeView;
	import com.skt.common_hr.work_sac.view.components.ReqVacationView;
	import com.skt.common_hr.work_sac.view.components.ReqWorkTimeView;
	import com.skt.common_hr.work_sac.view.components.WorkTimeOverView;
	import com.wcl.controls.calendar.CalendarDisplayEvent;
	import com.wcl.utils.DateUtil;
	
	import mx.collections.ArrayCollection;
	import mx.core.IFlexDisplayObject;
	import mx.formatters.DateFormatter;
	import mx.managers.PopUpManager;
	import mx.resources.ResourceManager;
	
	import org.puremvc.as3.multicore.interfaces.INotification;
	
	public class WorkTimeMediator extends OverViewMediator
	{
		public static const NAME:String = "WorkTimeMediator"; 
		
		private var bMorningOT:Boolean = false;
		
		/**
		* 생성자
		* 
		* @param
		* @return void
		*/
        public function WorkTimeMediator( viewComponent:Object )
        {
            super( NAME, viewComponent );
        }
 		
		/**
		* View를 초기화 한다.
		*	- View에 기본사항을 출력하고 data를 load
		* @param
		* @return void
		*/
		override protected function initializeView():void
 		{
 			super.initializeView();
			preloadData();
 			//buildTestData();
 		}
 		
 		/**
		 * 근태관리에 앞서 필요한 데이터를 모두 로드한다.
		 * 
		 * @param
		 * @return void
		 */
		private function preloadData():void
 		{
			// 휴가 종류 코드를 로드한다.
  			var codeProxy:VacationCodeProxy = facade.retrieveProxy(VacationCodeProxy.NAME) as VacationCodeProxy;
 			codeProxy.load();

			//var deniedProxy:DeniedWorkTimeProxy = facade.retrieveProxy(DeniedWorkTimeProxy.NAME) as DeniedWorkTimeProxy;
			//deniedProxy.loadList(GlobalVars.myPernr);

			// 휴가일수 안내를 로드한다.
			loadVacationQuota();

 			loadDateRange();
 			
			// 초과근무 Sum를 로드한다. - 현업 요청으로 삭제   2009.4.1
 			//loadOverTime(DateUtil.toYYYYMMString(new Date()));
 		}
 		
 		override protected function activatedView():void
 		{
 			setEventListeners();
 			view.tabView.selectedIndex = 0;
 			view.currentCalendarDate = DateUtil.todayNoTime();
 		}
 		
 		override protected function closedView():void
 		{
 			removeEventListeners();
 		}
 		
 		private function setEventListeners():void
 		{
 			view.addEventListener(WorkTimeEvent.CHANGED_MONTH, onChangedMonth);		// Calendar에서 월이 변경되어 있을때
 			view.calendar.addEventListener(CalendarDisplayEvent.DAY_CLICK, onCalendarDayClick);
 			view.addEventListener(WorkTimeEvent.SELECTED_VACATION, onSelectedVacation);
 			view.addEventListener(WorkTimeEvent.SELECTED_WORKTIME, onSelectedWorkTime);
 			view.addEventListener(WorkTimeEvent.MODIFY_WORKTIME, onModifyWorkTime);
 			view.addEventListener(WorkTimeEvent.MODIFY_VACATION, onModifyVacation);
 			view.addEventListener(WorkTimeEvent.READ_WORKTIME, onReadWorkTime);
 			view.addEventListener(WorkTimeEvent.READ_VACATION, onReadVacation);

 			view.addEventListener(WorkTimeEvent.CHANGED_RANGE, onChangedRange);		// 리스트 조회에서 조회 범위가 변경되었을 때

			/*
 			view.addEventListener(LoadReqVacationListEvent.LoadReqVacationList, loadReqVacation);
 			view.addEventListener(WorkTimeOverView.STARTUP_REQ_VACATION, startupReqVacation);
 			view.addEventListener(WorkTimeOverView.STARTUP_REQ_WORKTIME, startupReqWorkTime);
 			view.addEventListener(WorkTimeOverView.STARTUP_REQ_FOR_OTHERS, startupReqForOthers);
 			//view.addEventListener(DateEvent.CHANGED_DATE, onChangedDate);
 			*/
 		}
 		
		private function removeEventListeners():void
 		{
 			view.removeEventListener(WorkTimeEvent.CHANGED_MONTH, onChangedMonth);		// Calendar에서 월이 변경되어 있을때
 			view.removeEventListener(WorkTimeEvent.SELECTED_VACATION, onSelectedVacation);
 			view.removeEventListener(WorkTimeEvent.SELECTED_WORKTIME, onSelectedWorkTime);
 			view.removeEventListener(WorkTimeEvent.MODIFY_WORKTIME, onModifyWorkTime);
 			view.removeEventListener(WorkTimeEvent.MODIFY_VACATION, onModifyVacation);
 			view.removeEventListener(WorkTimeEvent.READ_WORKTIME, onReadWorkTime);
 			view.removeEventListener(WorkTimeEvent.READ_VACATION, onReadVacation);

 			view.removeEventListener(WorkTimeEvent.CHANGED_RANGE, onChangedRange);		// 리스트 조회에서 조회 범위가 변경되었을 때
 			view.calendar.removeEventListener(CalendarDisplayEvent.DAY_CLICK, onCalendarDayClick);
			/*
 			view.removeEventListener(LoadReqVacationListEvent.LoadReqVacationList, loadReqVacation);
 			view.removeEventListener(WorkTimeOverView.STARTUP_REQ_VACATION, startupReqVacation);
 			view.removeEventListener(WorkTimeOverView.STARTUP_REQ_WORKTIME, startupReqWorkTime);
 			view.removeEventListener(WorkTimeOverView.STARTUP_REQ_FOR_OTHERS, startupReqForOthers);
 			//view.removeEventListener(DateEvent.CHANGED_DATE, onChangedDate);
 			*/
 		}

		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Process MVC Messages
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		* 본 Class에서 처리해야할 Noti들을 등록한다.
		* 
		* @param
		* @return void
		*/
		override public function listNotificationInterests():Array 
		{
			return basicInterestMessages.concat( [
					WorkFacade.LOAD_CALENDAR_WORKORDER_COMPLETE,
					WorkFacade.LOAD_CALENDAR_COMPLETE,
					WorkFacade.LOAD_CALENDAR_FAILED,
					WorkFacade.LOAD_DATERANGE_COMPLETE,
					WorkFacade.LOAD_DATERANGE_FAILED,
					WorkFacade.LOAD_TEAMVACATION_COMPLETE,
					WorkFacade.LOAD_TEAMVACATION_FAILED,
					WorkFacade.LOAD_VACATIONLIST_COMPLETE,
					WorkFacade.LOAD_VACATIONLIST_FAILED,
					WorkFacade.LOAD_REQ_VACATION_COMPLETE,
					WorkFacade.LOAD_REQ_VACATION_FAILED,
					WorkFacade.LOAD_VACATION_QUOTA_COMPLETE,
					WorkFacade.LOAD_VACATION_QUOTA_FAILED,
					WorkFacade.LOAD_VACATION_CODE_COMPLETE,
					WorkFacade.LOAD_VACATION_CODE_FAILED,
					WorkFacade.LOAD_OVERTIME_SUM_COMPLETE,
					WorkFacade.LOAD_OVERTIME_SUM_FAILED,
					WorkFacade.LOAD_DENIED_WORKTIME_COMPLETE,
					WorkFacade.SUCCEED_REQ_WORKTIME,
					WorkFacade.CANCEL_REQ_WORKTIME
					]);
		}
		

		/**
		* Noti별로 처리한다.
		* 
		* @param
		* @return void
		*/
		override public function handleNotification(note:INotification):void
		{
			super.handleNotification(note);
			switch(note.getName()) 
			{
				case WorkFacade.LOAD_CALENDAR_WORKORDER_COMPLETE: 
					setWorkOrder(note.getBody() as CalendarProxy);
				break;
				
				case WorkFacade.LOAD_CALENDAR_COMPLETE:
					setCalendar(note.getBody() as CalendarProxy);
					setOTList(note.getBody() as CalendarProxy);
					//setStatusMessage("근무/휴가 데이터가  로드되었습니다.");
					break;
				case WorkFacade.LOAD_CALENDAR_FAILED:
					CommonAlert.showMessage(commonFacade.bundle, "ALERT_FAILED_LOAD_CALENDAR", null, "ALERT_TITLE_SYSTEM_ERROR");
					break;
				case WorkFacade.LOAD_TEAMVACATION_COMPLETE:
					//view.teamVacationList = (note.getBody() as TeamVacationProxy).teamVacationList;
					view.teamVacationList = getTeamList((note.getBody() as TeamVacationProxy));
					break;
				case WorkFacade.LOAD_VACATIONLIST_COMPLETE:
					view.myVacationList = (note.getBody() as VacationListProxy).vacationList;
					break;
				case WorkFacade.LOAD_VACATION_QUOTA_COMPLETE:
					trace("loaded quota");
					view.quotaList = (note.getBody() as VacationQuotaProxy).quotaList;
					view.quotaList2 = (note.getBody() as VacationQuotaProxy).quotaList2;
					//Alert.show("load quota : " + view.quotaList.length);
					break;
				case WorkFacade.LOAD_VACATION_CODE_COMPLETE:
					//view.vacationCodeList = (note.getBody() as VacationCodeProxy).codeList;
					//onAddRecord(new Event(""));
					break;
				case WorkFacade.LOAD_OVERTIME_SUM_COMPLETE:
					view.overtimeList = (note.getBody() as OverTimeSumProxy).sumList;
					break;
				case WorkFacade.LOAD_DATERANGE_COMPLETE:
					var rangeProxy:DateRangeProxy = note.getBody() as DateRangeProxy;
					//view.myCalendar.setInputRanges(rangeProxy.vacationRange, rangeProxy.workTimeRange);
					trace(rangeProxy.vacationRange.start + ", " + rangeProxy.vacationRange.end);
					view.calendar.setClickableRanges(rangeProxy.vacationRange, rangeProxy.workTimeRange);
					break;
				case WorkFacade.LOAD_DATERANGE_FAILED:
					trace("Failed to DateRange");
					break;
				case WorkFacade.SUCCEED_REQ_WORKTIME:
				case WorkFacade.CANCEL_REQ_WORKTIME:
					loadCalendarData(DateUtil.toYYYYMMString(view.currentCalendarDate));
					break;
				default:
					//trace(this.instanceID+"에서 처리 안된 Noti가 검출됨 : " + note.getBody());
					break;
			}
		}
		
/*		
		private function setCalendar(proxy:CalendarProxy):void
		{
			var eventList:ArrayCollection = new ArrayCollection;
			var event:CalendarEvent;
			//
			for each(var dateVO:DateVO in proxy.holidayList)
			{
				event = new CalendarEvent();
				event.type = CalendarEvent.EVENT_TYPE_HOLIDAY;
				event.title = dateVO.DTEXT;
				event.start = event.end	= dateVO.DATUM;
				eventList.addItem(event);
			}
			
			for each(var vacation:VacationVO in proxy.vacationList)
			{
				event = new CalendarEvent();
				event.type = CalendarEvent.EVENT_TYPE_NORMAL;
				if(vacation.DGBN=="2") {
					event.title = vacation.AWATX;
					event.allDay = false;
					event.summary = "여기에 툴팁이 들어갑니다.";//vacation.TEXT1;
					event.start = vacation.BEGDA;
					event.start.hours = vacation.BEGUZ.hours;
					event.start.minutes =vacation.BEGUZ.minutes;
					event.end = vacation.ENDDA;
					event.color = 0xFF0000;
				}
				else {
					event.title = vacation.AWATX;
					event.allDay = true;
					event.summary = "여기에 툴팁이 들어갑니다.";//vacation.TEXT1;
					event.start = vacation.BEGDA;
					event.end = vacation.ENDDA;
					event.color = 0xFF0000;
				}
				eventList.addItem(event);
			}
			view.calendarEvents = eventList;
		}
*/
		private function setCalendar(proxy:CalendarProxy):void
		{
			view.bHoliVacation  = proxy.bHoliVacation;
			view.holidayList 	= toCalendarHoliday(proxy.holidayList);
			view.vacationList 	= toCalendarItems(proxy.vacationList);
			bMorningOT = proxy.bMorningOT;
			
			// bgh 20110426
			// 기본 달력 셋팅값을 받아온후 사전근무지시 처리 호출
			
			// ace일경우에만.. 호출함 20110628
			if(Variables.company == 'SAC') {
 				var dateProxy:CalendarProxy = facade.retrieveProxy(CalendarProxy.NAME) as CalendarProxy;
 				dateProxy.loadWorkOrder(Variables.myPernr, view.currentCalendarDate );				
			}

 						
			//view.workOrderList 	= toCalendarHoliday(proxy.workOrderList);
		}

		private function setWorkOrder(proxy:CalendarProxy):void {
			view.workOrderList 	= proxy.workOrderList;
		}


		private function setOTList(proxy:CalendarProxy):void
		{
			var otList:ArrayCollection = new ArrayCollection();
			var OT011:Object = new Object();	OT011.gubun = "평일";		OT011.time = 0;
			var OT012:Object = new Object();	OT012.gubun = "평일야간";	OT012.time = 0;
			var OT021:Object = new Object();	OT021.gubun = "휴일";		OT021.time = 0;
			var OT022:Object = new Object();	OT022.gubun = "휴일야간";	OT022.time = 0;
			var OT023:Object = new Object();	OT023.time = 0;
			if(Variables.company=="SAC"){
				OT023.gubun = "휴일심야";	
			}	else {
				OT023.gubun = "평일가산";
			}
				
			
			
			for each(var vo:VacationVO in proxy.vacationList) {
				if(vo.WSTATUS == "2" || vo.WSTATUS == "3") {
					if(vo.AWART == "2010") {
						OT011.time += vo.OT011;
						OT012.time += vo.OT012;
						OT021.time += vo.OT021;
						OT022.time += vo.OT022;
						OT023.time += vo.OT023;
					}
				}
			}
			otList.addItem(OT011);
			otList.addItem(OT012);
			otList.addItem(OT021);
			otList.addItem(OT022);
			otList.addItem(OT023);
			view.otList = otList;
		}
		
		// 본인 기록은 제외
		private function getTeamList(proxy:TeamVacationProxy):ArrayCollection
		{
			var arr:ArrayCollection = new ArrayCollection();
			for each(var vo:TeamVacationVO in proxy.teamVacationList) {
				trace(Variables.myPernr);
				if(vo.PERNR!=Variables.myPernr) {
					arr.addItem(vo);
				}
			}
			return arr;
		}
		
		private function toCalendarHoliday(src:ArrayCollection):ArrayCollection
		{
			var coll:ArrayCollection = new ArrayCollection();
			for each(var rec:DateVO in src) {
				var vo:Holiday = new Holiday();
				vo.DATUM = new Date(rec.DATUM);
				vo.DTYPE = rec.DTYPE;
				vo.DTEXT = rec.DTEXT;
				coll.addItem(vo);
			}
			return coll;
		}
		
		private var buttonStyleList:Array = ["btn02Return04", "btn02barBlue", "btn02barBlue", "btn02barPink", "btn02barGreen", ""];
		private function toCalendarItems(src:ArrayCollection):ArrayCollection
		{
			var coll:ArrayCollection = new ArrayCollection();
			var tempArr:Array = new Array(); 
			for each(var rec:VacationVO in src) {
				if(rec.WSTATUS =="1" && (rec.DGBN=="1" || rec.DGBN=="2")) {	// 휴가 혹은 근태일경우 임시저장인것은 삭제
					tempArr.push({GWAREKEY: rec.GWAREKEY});
				}
				else {
					var vo:DailyItem = new DailyItem();
					vo.WGBN				= rec.WGBN;
					vo.WGBNT			= rec.WGBNT;
					vo.DGBN				= rec.DGBN;
					vo.DGBNT			= rec.DGBNT;
					vo.AWART			= rec.AWART;
					vo.AWATX			= rec.AWATX;
					vo.BEGDA			= new Date(rec.BEGDA);
					vo.ENDDA			= new Date(rec.ENDDA);
					vo.BEGUZ			= new Date(rec.BEGUZ);
					vo.ENDUZ			= new Date(rec.ENDUZ);
					vo.WSTATUS			= rec.WSTATUS;
					vo.WSTATX			= rec.WSTATX;
					vo.TABNR			= rec.TABNR;
					vo.GUBUN			= rec.GUBUN;
					vo.TEXT1			= rec.TEXT1;
					vo.GWAREKEY			= rec.GWAREKEY;
					vo.confirmTime		= rec.confirmTime;
					
					//20110630
					vo.isInsertFromCong = rec.isInsertFromCong;
					
					vo.label = vo.AWATX;
					if(vo.WSTATUS=="4" && (vo.DGBN=="1" || vo.DGBN=="2")) {	// 반려인 경우
						vo.clickable = true;
						vo.tootip = ResourceManager.getInstance().getString(commonFacade.bundle, "TOOLTIP_REJECT", null, Variables.current_locale);
						vo.style = buttonStyleList[0];
					}
					else {
						vo.clickable = false;
						vo.tootip = buildToolTip(vo);
						//vo.GWAREKEY = "";
						vo.style = buttonStyleList[parseInt(vo.DGBN)];
					}
					coll.addItem(vo);
				}
			}
			if(tempArr.length>0) {
				deleteTempRecords(tempArr);
			}
			return coll;
		}
		
		
		private function buildToolTip(vo:DailyItem):String
		{
			var tmp:String = "";
			tmp = "[" + vo.WSTATX + "] ";
			switch(vo.DGBN) {
				case '1':		// 휴가...
					tmp += vo.TEXT1;		
					break;
				case '2':			// 근무
					tmp += "인정시간 : " + vo.confirmTime;		
					break;
				case '3':						// 출장
					tmp += vo.TEXT1;		
					break;
				case '4':						// 교육
					tmp += vo.TEXT1;		
					break;
			}
			return tmp;			
		}
		
		
 		private function deleteTempRecords(table:Array):void
 		{
 			var proxy:ReqWorkTimeProxy = facade.retrieveProxy(ReqWorkTimeProxy.NAME) as ReqWorkTimeProxy;
 			proxy.deleteWorkTime(table);
 		}
		
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Event handler (from View, Internal or....)
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
  		private function onChangedMonth(event:WorkTimeEvent):void
 		{
  			var targetMonth:String = DateUtil.toYYYYMMString(event.start);//event.beginDate.fullYear.toString() + ((event.beginDate.month+1<10)?"0":"") + (event.beginDate.month+1).toString();
 			loadCalendarData(targetMonth);
 			loadTeamVacation(targetMonth);
 			//loadOverTime(targetMonth);
 			//view.selectedDate = event.beginDate;
 		}
 		
 		private function onCalendarDayClick(e:CalendarDisplayEvent):void
 		{
 			//trace(e.dateTime.toString());
 			//execReqWorktimeView(e.dateTime);
 		}
		
 		private function onChangedRange(event:WorkTimeEvent):void
 		{
 			var proxy:VacationListProxy = facade.retrieveProxy(VacationListProxy.NAME) as VacationListProxy;
 			var dateFormat:DateFormatter = new DateFormatter();
 			dateFormat.formatString = "YYYYMM";
 			
 			proxy.load(Variables.myPernr, event.start, event.end);	
 		}
 		


 		private var reqVacationView:IFlexDisplayObject = null;
 		private function onSelectedVacation(event:WorkTimeEvent):void
 		{
 			var reqMediator:ReqVacationMediator = facade.retrieveMediator(ReqVacationMediator.NAME) as ReqVacationMediator;;
 			if(reqMediator==null) {
	 			reqVacationView = PopUpManager.createPopUp(view.root, ReqVacationView, true);
	 			PopUpManager.centerPopUp(reqVacationView);
				
				reqMediator = new ReqVacationMediator(reqVacationView)	
	 			facade.registerMediator(reqMediator);
	 		}
	 		else {
	 			PopUpManager.addPopUp(reqVacationView, view.root, true);
	 			reqMediator = facade.retrieveMediator(ReqVacationMediator.NAME) as ReqVacationMediator;
	 		}
	 		(reqVacationView as ReqVacationView).setFocus();
	 		(reqVacationView as ReqVacationView).lbHelp1.visible = false;
	 		(reqVacationView as ReqVacationView).lbHelp2.visible = false;
	 		(reqVacationView as ReqVacationView).lbHelp3.visible = false;
	 		(reqVacationView as ReqVacationView).lbHelp4.visible = false;
	 		
	 		(reqVacationView as ReqVacationView).lbHelp7_1.visible = false;
	 		(reqVacationView as ReqVacationView).lbHelp7_2.visible = false;
	 		(reqVacationView as ReqVacationView).lbHelp7_2_1.visible = false;
	 		(reqVacationView as ReqVacationView).lbHelp7_3.visible = false;
	 		(reqVacationView as ReqVacationView).lbHelp7_4.visible = false;
	 		
	 		
	 		reqMediator.exec(event.start);
 		}
 		
 		
 		private var reqWorkTime:ReqWorkTimeView;
 		private function onSelectedWorkTime(event:WorkTimeEvent):void
 		{
 			var reqMediator:ReqWorkTimeMediator = facade.retrieveMediator(ReqWorkTimeMediator.NAME) as ReqWorkTimeMediator;
 			if(reqMediator==null) {
 				reqWorkTime = PopUpManager.createPopUp(view.root, ReqWorkTimeView, true) as ReqWorkTimeView;
 				PopUpManager.centerPopUp(reqWorkTime);
				
				reqMediator = new ReqWorkTimeMediator(reqWorkTime)	
	 			facade.registerMediator(reqMediator);
 			}
 			else {
	 			PopUpManager.addPopUp(reqWorkTime, view.root, true);
 			}
 			reqWorkTime.setFocus();
 			reqMediator.exec(event.start, bMorningOT);
 		}
 		
 		private function onModifyWorkTime(event:WorkTimeEvent):void
 		{
 			var keyNum:Number = parseInt(event.key);
 			if(isNaN(keyNum) || keyNum == 0) {
				CommonAlert.showMessage(commonFacade.bundle, "본인이 입력한 데이터만 수정할 수 있습니다.", null, "확인");
 			}
 			else {
 				modifyWorkTime(event.key, event.start);
 			}
 		}

 		private function onReadWorkTime(event:WorkTimeEvent):void
 		{
 			var keyNum:Number = parseInt(event.key);
 			if(isNaN(keyNum) || keyNum == 0) {
				CommonAlert.showMessage(commonFacade.bundle, "본인이 입력한 데이터만 조회할 수 있습니다.", null, "확인");
 			}
 			else {
 				readWorkTime(event.key, event.start);
 			}
 		}

		private var modWorkTime:ModWorkTimeView;
		private function modifyWorkTime(key:String, baseDate:Date):void
		{
			var modMediator:ModWorkTimeMediator = facade.retrieveMediator(ModWorkTimeMediator.NAME) as ModWorkTimeMediator;
			if(modMediator==null) {
	 			modWorkTime = PopUpManager.createPopUp(view.root, ModWorkTimeView, true) as ModWorkTimeView;
	 			PopUpManager.centerPopUp(modWorkTime);
	 			
				modMediator = new ModWorkTimeMediator(modWorkTime);	
				facade.registerMediator(modMediator);
			}	
			else {
				PopUpManager.addPopUp(modWorkTime, view.root, true);
			}
			modWorkTime.setFocus();
			modMediator.exec(baseDate, key);
		}

		private var readWorkTimeView:ReadWorkTimeView=null;
		private function readWorkTime(key:String, baseDate:Date, propText1:String=''):void
		{
			var readMediator:ReadWorkTimeMediator = facade.retrieveMediator(ReadWorkTimeMediator.NAME) as ReadWorkTimeMediator;
			if(readMediator==null) {
	 			readWorkTimeView = PopUpManager.createPopUp(view.root, ReadWorkTimeView, true) as ReadWorkTimeView;
	 			PopUpManager.centerPopUp(readWorkTimeView);
	 			
				readMediator = new ReadWorkTimeMediator(readWorkTimeView);	
				facade.registerMediator(readMediator);
			}	
			else {
				PopUpManager.addPopUp(readWorkTimeView, view.root, true);
			}
			readWorkTimeView.setFocus();
			readMediator.exec(baseDate, key, propText1);
		}

 		private function onModifyVacation(event:WorkTimeEvent):void
 		{
  			var keyNum:Number = parseInt(event.key);
 			trace("휴가변경");
 			if(isNaN(keyNum) || keyNum == 0) {
				CommonAlert.showMessage(commonFacade.bundle, "본인이 입력한 데이터만 수정할 수 있습니다.", null, "확인");
 			}
 			else {
 				modifyVacation(event.key, event.start);
			}
 		}
		
		private var modVacation:ModVacationView;
 		private function modifyVacation(key:String, baseDate:Date):void
		{
			var modMediator:ModVacationMediator = facade.retrieveMediator(ModVacationMediator.NAME) as ModVacationMediator;
			if(modMediator==null) {
	 			modVacation = PopUpManager.createPopUp(view.root, ModVacationView, true) as ModVacationView;
	 			PopUpManager.centerPopUp(modVacation);
				
				modMediator = new ModVacationMediator(modVacation);
				facade.registerMediator(modMediator);	
			}
			else {
				PopUpManager.addPopUp(modVacation, view.root, true);
			}
			modVacation.setFocus();
			modMediator.exec(baseDate, key);			
		}

 		private function onReadVacation(event:WorkTimeEvent):void
 		{
  			trace("휴가조회");
  			var keyNum:Number = parseInt(event.key);
 			if(isNaN(keyNum) || keyNum == 0) {
				CommonAlert.showMessage(commonFacade.bundle, "본인이 입력한 데이터만 조회할 수 있습니다.", null, "확인");
 			}
 			else {
				readVacation(event.key, event.start, event.isInsertFromCong);
			}
 		}

		private var readVacationView:ReadVacationView = null;
 		private function readVacation(key:String, baseDate:Date, isInsertFromCong:Boolean=false):void
		{
			var readMediator:ReadVacationMediator = facade.retrieveMediator(ReadVacationMediator.NAME) as ReadVacationMediator;
			if(readMediator==null) {
	 			readVacationView = PopUpManager.createPopUp(view.root, ReadVacationView, true) as ReadVacationView;
	 			PopUpManager.centerPopUp(readVacationView);
				
				readMediator = new ReadVacationMediator(readVacationView);
				facade.registerMediator(readMediator);	
			}
			else {
				PopUpManager.addPopUp(readVacationView, view.root, true);
			}
			readVacationView.setFocus();
			readMediator.exec(baseDate, key, isInsertFromCong);			
		}


  		private function loadCalendarData(month:String):void
 		{
 			var dateProxy:CalendarProxy = facade.retrieveProxy(CalendarProxy.NAME) as CalendarProxy;
 			dateProxy.load(Variables.myPernr, month);
 		}
 	

		private function loadTeamVacation(month:String):void
 		{
  			var teamVacationProxy:TeamVacationProxy = facade.retrieveProxy(TeamVacationProxy.NAME) as TeamVacationProxy;
 			teamVacationProxy.load(Variables.myPernr, month);
		}

 		private function loadVacationQuota():void
 		{
 			var quotaProxy:VacationQuotaProxy = facade.retrieveProxy(VacationQuotaProxy.NAME) as VacationQuotaProxy;
 			quotaProxy.load(Variables.myPernr, DateUtil.thisYear().toString());
 		}

 		
 		private function loadOverTime(month:String):void
 		{
 			var overtimeProxy:OverTimeSumProxy = facade.retrieveProxy(OverTimeSumProxy.NAME) as OverTimeSumProxy;
 			overtimeProxy.load(Variables.myPernr, month);
 		}
 		

		private function loadDateRange():void
 		{
 			var proxy:DateRangeProxy = facade.retrieveProxy(DateRangeProxy.NAME) as DateRangeProxy;
 			proxy.load();
 		}
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Utility Functions
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
        private function get view():WorkTimeOverView
        {
            return viewComponent as WorkTimeOverView;
        }
	}
}